import { createSlice } from '@reduxjs/toolkit';

export const menuSlice = createSlice({
    name: 'menu',
    initialState: {
        list: false
    },
    reducers: {
        refreshMenus: (state, action) => {
            localStorage.setItem('menus', JSON.stringify(action.payload));
            state.list = !state.list;
        },
        getStorageMenus: () => {
            let menus = localStorage.getItem('menus');
            return menus ? JSON.parse(menus) : [];
        },
        clearMenus: (state) => {
            localStorage.removeItem('menus');
            state.list = !state.list;
        }
    }
});

export const { refreshMenus, getStorageMenus, clearMenus } = menuSlice.actions;
export default menuSlice.reducer;